{extend name="pub/base" /}
{block name="head"}
<title>订单管理</title>
<style>
    /** 数据表格中的select尺寸调整 */
    .layui-table-view .layui-table-cell .layui-select-title .layui-input {
        height: 28px;
        line-height: 28px;
    }

    .layui-table-view [lay-size="lg"] .layui-table-cell .layui-select-title .layui-input {
        height: 40px;
        line-height: 40px;
    }

    .layui-table-view [lay-size="lg"] .layui-table-cell .layui-select-title .layui-input {
        height: 40px;
        line-height: 40px;
    }

    .layui-table-view [lay-size="sm"] .layui-table-cell .layui-select-title .layui-input {
        height: 20px;
        line-height: 20px;
    }

    .layui-table-view [lay-size="sm"] .layui-table-cell .layui-btn-xs {
        height: 18px;
        line-height: 18px;
    }
</style>
{/block}
{block name="main"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格工具栏 -->
            <form class="layui-form toolbar table-tool-mini">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input id="user_id" class="layui-input" type="text" placeholder="用户id"/>
                        </div>
                    </div>

                    <div class="layui-inline" expand-show="">
                        <div class="layui-input-inline">
                            <select id="usage">
                                <option value="">所有</option>
                                <option value="1">充值</option>
                                <option value="2">购买vip</option>
                                <option value="3">购买章节</option>
                                <option value="4">奖励</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline" style="padding-right: 110px;">
                        <button class="layui-btn icon-btn" lay-filter="tbBasicTbSearch" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                </div>
            </form>
            <!-- 数据表格 -->
            <table id="tbBasicTable" lay-filter="tbBasicTable"></table>
        </div>
    </div>

    <div class="layui-card">
        <div class="layui-card-body">
            交流和反馈建议请加QQ群：780362399
        </div>
    </div>

    <!-- 表格操作列 -->
    <script type="text/html" id="tbBasicTbBar">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
</div>

{/block}
{block name="js"}
<script>
    layui.use(['table', 'dropdown', 'form'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var dropdown = layui.dropdown;
        var form = layui.form

        /* 表格工具条点击事件 */
        table.on('tool(tbBasicTable)', function (obj) {
            var data = obj.data; // 获得当前行数据
            if (obj.event === 'del') { // 删除
                layer.confirm('确认要删除吗？', function (index) {
                    $.ajax({
                        type: 'POST',
                        url: "{:adminurl('delete')}",
                        data: {id: data.id},
                        dataType: 'json',
                        success: function (res) {
                            if (res.err == 0) { //删除成功
                                layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                                    location.reload();
                                });
                            } else {
                                layer.msg(res.msg, {icon: 2}, function () {
                                    location.reload();
                                });
                            }
                        },
                        error: function (res) {
                            layer.msg(res);
                        },
                    });
                });
            }
            dropdown.hideAll();
        });

        /* 渲染表格 */
        var insTb = table.render({
            elem: '#tbBasicTable',
            url: "{:adminurl('payment/flist')}",
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'checkbox'},
                {field: 'id', title: 'ID', align: 'center', sort: true},
                {field: 'user_id', title: '用户ID', align: 'center', sort: true},
                {field: 'money', title: '金额', align: 'center', sort: true},
                {
                    field: 'usage', title: '用途', templet: function (d) {
                        var s = ''
                        if (d.usage === 1) {
                            s = '充值'
                        } else if (d.usage === 2){
                            s = '购买vip'
                        } else if (d.usage === 3){
                            s = '购买章节'
                        } else if (d.usage === 4){
                            s = '奖励'
                        }
                        return s;
                    }, align: 'center', sort: true
                },
                {field: 'summary', title: '备注', align: 'center', sort: true},
                {field: 'create_time', title: '发生时间', align: 'center', sort: true},
                {title: '操作', toolbar: '#tbBasicTbBar', align: 'center', minWidth: 200}
            ]]
        });

        form.on('submit(tbBasicTbSearch)', function (data) {
            var user_id = $('#user_id').val()
            var usage = $('#usage').val()
            table.render({
                elem: '#tbBasicTable',
                url: '{:adminurl("flist")}?usage=' + usage + '&user_id=' + user_id,
                page: true,
                cellMinWidth: 100,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID', align: 'center', sort: true},
                    {field: 'user_id', title: '用户ID', align: 'center', sort: true},
                    {field: 'money', title: '金额', align: 'center', sort: true},
                    {
                        field: 'usage', title: '用途', templet: function (d) {
                            var s = ''
                            if (d.usage === 1) {
                                s = '充值'
                            } else if (d.usage === 2){
                                s = '购买vip'
                            } else if (d.usage === 3){
                                s = '购买章节'
                            } else if (d.usage === 4){
                                s = '奖励'
                            }
                            return s;
                        }, align: 'center', sort: true
                    },
                    {field: 'summary', title: '备注', align: 'center', sort: true},
                    {field: 'create_time', title: '发生时间', align: 'center', sort: true},
                    {title: '操作', toolbar: '#tbBasicTbBar', align: 'center', minWidth: 200}
                ]]
            });
            return false;
        });
    });
</script>
{/block}
